Formating, data transformation and use of the Statbank API

The table collection, ’Greenland in numbers’ and the Greenlandic development goals are calculated and presented using numbers from the Statbank.

 

Data query, processing, and formatting is documented by allowing access to the programming code used to make the presentation. The code is written using the statistical programming language R, which can be downloaded for free on https://cran.r-project.org/

 

An R package called statgl has been developed to ease and standardize the R programming at Statistics Greenland. A development version is available on Github, and can be installed in R-Studio using the command:

 

devtools::install_github("StatisticsGreenland/statgl")

 

This assumes that the devtools package has already been installed:

 

install.packages("devtools")

Data visualization

The R package uses the graphics library ggplot2 for data visualization. This includes functions to define custom themes and color scales, which can be added as layers to existing ggplot objects. This is a typical ggplot:

 

library(ggplot2)

ggplot(data = mpg, mapping = aes(x = displ, y = hwy, color = class)) +

  geom_point()

 

 

 

 

Theme can be added by using the theme_statgl() function from the statgl-package:

 

library(ggplot2)

library(statgl)

 

ggplot(data = mpg, mapping = aes(x = displ, y = hwy, color = class)) +

  geom_point() +

  theme_statgl()

 

 

Custom color scale can be added using the function scale_color_statgl():

 

library(ggplot2)

library(statgl)

 

ggplot(data = mpg, mapping = aes(x = displ, y = hwy, color = class)) +

  geom_point() +

  theme_statgl() +

  scale_color_statgl()

 

 

 

A similar function is used for bar charts, called scale_fill_statgl().

Tables

The R package uses the kableExtra library to draw HTML tables for use on the website. The simplest function is called statgl_table(), which returns an HTML table in a specific format, if a data frame is provided:

 

library(statgl)

statgl_table(df = head(mtcars))

 

 

More information about the package is available on Statistics Greenland’s Github page.